home *** CD-ROM | disk | FTP | other *** search
/ Day Cry / Day Cry CD.bin / oh_towns / taropyon / splib / splib.lzh / PRG / LHX / USRLIB.C < prev    next >
C/C++ Source or Header  |  1993-12-07  |  9KB  |  440 lines

  1. /*************************************************************************
  2. *    "usrlib.c"
  3. *-------------------------------------------------------------------------
  4. *                                                            By TaroPYON
  5. *************************************************************************/
  6.  
  7. #include    <stdio.h>
  8. #include    <stdlib.h>
  9. #include    <stdarg.h>
  10. #include    <string.h>
  11. #include    <ctype.h>
  12. #include    <msdos.cf>
  13.  
  14. #include    <loader.h>
  15. #include    <egb.h>
  16.  
  17. #include    "usrlib.h"
  18. #include    <disp.h>
  19. #include    <cnslib.h>
  20. #include    <dta.h>
  21. #include    <dialog.h>
  22. #include    <fslib.h>
  23. #include    <kyb.h>
  24. #include    <setint.h>
  25. #include    <keycode.h>
  26. #include    <event.h>
  27. #include    <sbar.h>
  28. #include    <mouse.h>
  29. #include    <moscur.h>
  30. #include    <spicon.h>
  31. #include    <egbmacro.h>
  32.  
  33. #include    "usrlib.h"
  34. #include    "lh.h"
  35.  
  36. #ifdef    __HIGHC__
  37. #    pragma    On(Align_labels);
  38. #endif
  39.  
  40. DTACTRL_T            *DtaCtrl = NULL;
  41. static CONST char    RECODENAME_DSPCTRL[] = "$DspCtrl";
  42. static CONST char    RECODENAME_MAINARG[] = "$MainArg";
  43. DLG_T                *LhxDlg = NULL;
  44. CNS_T                *LhxCns = NULL;
  45. EVT_T                *LhxEvt = NULL;
  46. SBAR_T                *LhxSbV = NULL;
  47.  
  48. #define                CNS_XS        (80)
  49. #define                CNS_YS        (24)
  50. #define                DLG_XS        (   4 + CNS_XS* 6 + 2+16+4)
  51. #define                DLG_YS        (20+4 + CNS_YS*12 + 4)
  52.  
  53. static                int        LhxCh;
  54. static                UINT    LhxEc;
  55.  
  56. #define                BREAK_CHECK()    {                            \
  57.     LhxCh = EVT_getkey( &LhxEc );                                \
  58.     if ( LhxCh == 3 || (LhxEc&0xFF14) == (KA_C|KA_BIT_CTRL) )    \
  59.         userbreak(0);                                            \
  60. }
  61.  
  62. #define    MAIN_EVT_CANCEL    (9999)
  63.  
  64. static    PLT_RGB    PltDat[16] =
  65. {
  66.     /* G R  B                                */
  67.     { 0, 0, 0},    /* C_BALCK                    */
  68.     { 0, 0, 0},    /* C_BLUE or C_THROUGH        */
  69.     { 7, 7, 8},    /* C_RED                    */
  70.     {12,12,13},    /* C_MAGENTA                */
  71.     { 6, 5, 7},    /* C_GREEN                    */
  72.     { 8, 7, 9},    /* C_CYAN                    */
  73.     {10, 9,11},    /* C_YELLOW                    */
  74.     {11,11,12},    /* C_WHITE                    */
  75.  
  76.     { 5, 5, 6},    /* C_HBALCK                    */
  77.     { 0, 0,11},    /* C_HBLUE                    */
  78.     { 0,11, 0},    /* C_HRED                    */
  79.     { 0,11,11},    /* C_HMAGENTA                */
  80.     {11, 0, 0},    /* C_HGEEN                    */
  81.     {11, 0,11},    /* C_HCYAN                    */
  82.     {11,11, 0},    /* C_HYELLOW                */
  83.     {14,14,15}    /* C_HWHITE                    */
  84. };
  85.  
  86. /*    #define    _LHX_DEBUG    */
  87.  
  88. #ifdef    _LHX_DEBUG
  89. static    int    _dspPosY = 0;
  90. #    define    DPUTS(s)    wrtstr((s),WRTPAGE(1),WRTADR(32,28+(_dspPosY++)*18),WRTCOL(C_HGREEN),WRTCOL(0),16)
  91. #else
  92. #    define    DPUTS(s)
  93. #endif
  94.  
  95.  
  96. void    LHX_dspFlush(void)
  97. {
  98.     LhxSbV->top = LhxCns->dspPos.lnD;
  99.     LhxSbV->dsp = LhxCns->dspYm;
  100.     LhxSbV->min = 0;
  101.     LhxSbV->max = LhxCns->linMaxD ? LhxCns->linMaxD - 1 : 0;
  102.     SBAR_Vredraw(LhxSbV);
  103. }
  104.  
  105. /*************************************************************************
  106. *    â_âCâìâAâOò\Īè╓Éö
  107. *************************************************************************/
  108.  
  109. static    void    dspFunc( DLG_T *dlg )
  110. {
  111.     int        evtPos = 0;
  112.     int        x1 = dlg->fr.x0;
  113.     int        y1 = dlg->fr.y0;
  114.     int        x2 = x1 + dlg->fr.xs - 1;
  115. //    int        y2 = y1 + dlg->fr.ys - 1;
  116.     int        cx1, cy1, cx2, cy2;
  117.     extern    char    title[];
  118.  
  119.     boxfHol( x1+2, y1+2, x2-2, y1+2+18, PSET, C_WHITE, C_HWHITE, C_DARK );
  120.     DSP_str( x1+4, y1+4, C_MBLACK, C_WHITE, 16, "%s", title );
  121.  
  122.     /*    [EXIT]â{â^âô    --------------------------------------------*/
  123.     {
  124.         CONST int    x = x2 - 18;
  125.         CONST int    y = y1 + 3;
  126.  
  127.         EGB_writeMode( EgbPtr, OPAQUE );
  128.         EGB_paintMode( EgbPtr, 0x022);
  129.         EGB_color( EgbPtr, 0, C_DARK );
  130.         EGB_color( EgbPtr, 1, C_WHITE );
  131.         _EGB_PUTBLOCKCOLOR(0, x, y, x+15, y+15, getds(), _icn16x16_closeBtn );
  132.         boxHol( x, y, x+15, y+15, PSET, C_HWHITE, C_DARK );
  133.         _EVT_SETMOS( LhxEvt, evtPos++, MAIN_EVT_CANCEL, MOSEVT_BTN, BTN_LEFT,
  134.             x, y, x+15, y+15, 0, NULL );
  135.    }
  136.  
  137.     /*    â_âCâAâìâOê┌ô«ùp    ----------------------------------------*/
  138.     _EVT_SETMOS( LhxEvt, evtPos++, 0, MOSEVT_NOACT|MOSEVT_QUICK, BTN_LEFT,
  139.         x1+2, y1+2, x2-2, y1+2+18, DLG_defMoveFunc, dlg );
  140.  
  141.     /* âRâôâ\ü[âïù╠êµ    */
  142.     cx1 = x1+4;
  143.     cy1 = y1+24;
  144.     cx2 = x1 + 4 + CNS_XS* 6 - 1;
  145.     cy2 = y1 +24 + CNS_YS*12 - 1;
  146.  
  147.     box( cx1-1, cy1-1, cx2+1, cy2+1, PSET, C_WHITE );
  148.     box( cx1-2, cy1-2, cx2+2, cy2+2, PSET, C_DARK  );
  149.     CNS_changeScnSize( LhxCns, cx1, cy1, cx2, cy2 );
  150.     CNS_flush( LhxCns, ERR, ERR);
  151.  
  152.     /* âXâNâìü[âïâoü[    */
  153.     SBAR_Vdsp( LhxSbV, cx2+5, cy1, 16, cy2-cy1+1 );
  154.     LHX_dspFlush();
  155. }
  156.  
  157. /*************************************************************************
  158. *    âXâNâìü[âïâoü[âTü[ârâXè╓Éö
  159. *************************************************************************/
  160.  
  161. static int        funcSbarV( int evtNo, SBAR_T *sbV )
  162. {
  163.     CNS_T    *cns = LhxCns;
  164.  
  165.     if ( cns->linMaxD < cns->dspYm )
  166.     {
  167.         sbV->top = 0;
  168.         return (0);
  169.     } else if ( sbV->top > cns->homeY )
  170.         sbV->top = cns->homeY;
  171.  
  172.     switch( evtNo )
  173.     {
  174.         case    SBEVT_SLIDE:
  175.             MOS_DEC();
  176.             CNS_jump( cns, sbV->top );
  177.             MOS_INC();
  178.             break;
  179.         case    SBEVT_INC:
  180.             if ( sbV->top <= cns->homeY )
  181.             {
  182.                 MOS_DEC();
  183.                 CNS_nextLine( cns, 1 );
  184.                 MOS_INC();
  185.             }
  186.             break;
  187.         case    SBEVT_DEC:
  188.             MOS_DEC();
  189.             CNS_prevLine( cns, 1 );
  190.             MOS_INC();
  191.             break;
  192.     }
  193.     return (0);
  194. }
  195.  
  196. static    void    hit_any_key(void)
  197. {
  198.     int        ch;
  199.     UINT    ec;
  200.  
  201.     LHX_puts("\n**** Hit any key *****\n");
  202.     MOS_curType(MOSCUR_NORMAL);
  203.     MOS_CON();
  204.  
  205.     for(;;)
  206.     {
  207.         int        ret;
  208.  
  209.         LHX_dspFlush();
  210.  
  211.         if ( (ret = EVT_chk(LhxEvt,EVTIGN_KEY)) >= 0 )
  212.         {
  213.             if ( ret == MAIN_EVT_CANCEL )
  214.                 break;
  215.         } else
  216.         {
  217.             ch = EVT_getkey(&ec);
  218.             if ( ch != 0xFFFF || (ec & 0xFF00) != 0xFF00 )
  219.             {    ec &= 0xFF14;
  220.                 switch( ec )
  221.                 {
  222.                     case    KA_UP:
  223.                     case    KA_W|KA_BIT_CTRL:
  224.                     case    KA_PREV:
  225.                         MOS_DEC();
  226.                         CNS_prevLine( LhxCns, 1 );
  227.                         MOS_INC();
  228.                         break;
  229.                     case    KA_DOWN:
  230.                     case    KA_Z|KA_BIT_CTRL:
  231.                     case    KA_NEXT:
  232.                         MOS_DEC();
  233.                         CNS_nextLine( LhxCns, 1 );
  234.                         MOS_INC();
  235.                         break;
  236.                     case    KA_UP|KA_BIT_SHIFT:
  237.                     case    KA_R|KA_BIT_CTRL:
  238.                         MOS_DEC();
  239.                         CNS_prevLine( LhxCns, LhxCns->dspYm );
  240.                         MOS_INC();
  241.                         break;
  242.                     case    KA_DOWN|KA_BIT_SHIFT:
  243.                     case    KA_C|KA_BIT_CTRL:
  244.                         MOS_DEC();
  245.                         CNS_nextLine( LhxCns, LhxCns->dspYm );
  246.                         MOS_INC();
  247.                         break;
  248.                     default:
  249.                         goto    LOOP_EXIT;
  250.                 }
  251.             } else
  252.                 EVT_idl();
  253.         }
  254.     }
  255. LOOP_EXIT:
  256.     return;
  257. }
  258.  
  259. int        USYS_init( int *argc, char **argv[], int _argc, char *_argv[] )
  260. {
  261.     DTARECODE_T    *dsp_recode = NULL;
  262.     DTARECODE_T    *arg_recode = NULL;
  263.     DSPCTRL        *dsp = NULL;
  264.  
  265.     *argc = _argc;
  266.     *argv = _argv;
  267.  
  268.     if ( DTA_isAtPcl() )
  269.     {
  270.         char        *args = "LHx";
  271.  
  272.         DPUTS("DTA_openCheck()");
  273.         if ( (DtaCtrl = DTA_openCheck()) != NULL )
  274.         {
  275.             if ( (dsp_recode = DTA_openRecode( DtaCtrl, RECODENAME_DSPCTRL)) != NULL )
  276.             {    /* ò\ĪâVâXâeâÇé╠Åεò±éáéΦ    */
  277.                 DPUTS("Get DspCtrl");
  278.                 dsp = dsp_recode->ptr;
  279.             }
  280.             if ( (arg_recode = DTA_openRecode( DtaCtrl, RECODENAME_MAINARG)) != NULL )
  281.             {    /* âpâëâüü[â^é╠ÄwÆΦéáéΦ    */
  282.                 DPUTS("Get argc/argv");
  283.                 args = arg_recode->ptr;
  284.             }
  285.         }
  286.         if ( (*argc = FS_argSet( args, argv )) < 1 )
  287.             return (ERR);
  288.     }
  289.  
  290.     set_ctrl_c();
  291.     set24h();
  292.  
  293.     /* ò\ĪâVâXâeâÇÅëè·ë╗    */
  294.     if ( DSP_pcl_sysInit( dsp ) )
  295.         return    (ERR);
  296.  
  297.     if ( dsp == NULL )
  298.         DSP_setPlt(PltDat);
  299.  
  300.     DSP_set_defFnt( FNTYPE_USR1 );
  301.     GetFnt12Ptr(0);
  302.     KBF_sysInit();
  303.  
  304.     /* âCâxâôâgùp    */
  305.     LhxEvt = EVT_alloc(NULL,8);
  306.     LhxSbV = SBAR_Vopen(LhxEvt, funcSbarV, NULL );
  307.     LhxCns = CNS_open();
  308.  
  309.     /* â_âCâAâìâOâIü[âvâô    */
  310.     LhxDlg = DLG_open( DLGPOS_CENTER_OF_SCN, DLGPOS_CENTER_OF_SCN,
  311.         DLG_XS, DLG_YS, C_DLGBASE, dspFunc, NULL );
  312.     if ( LhxEvt == NULL || LhxSbV == NULL || LhxDlg == NULL || LhxCns == NULL )
  313.         return (ERR);
  314.  
  315.     LhxCns->page = DspCtrl.writePage;
  316.     LhxSbV->attr |= (SBATT_SLIDEQUICK | SBATT_MAXADJUST);
  317.  
  318.     DLG_dsp(LhxDlg);
  319.  
  320.     return (NORMAL);
  321. }
  322.  
  323. void    USYS_term( int errLevel )
  324. {
  325.     hit_any_key();
  326.  
  327.     if ( LhxCns )
  328.     {
  329.         CNS_close( LhxCns );
  330.         LhxCns = NULL;
  331.     }
  332.     if ( LhxDlg )
  333.     {    DLG_close( LhxDlg );
  334.         LhxDlg = NULL;
  335.     }
  336.  
  337.     if ( DtaCtrl )
  338.     {
  339.         if ( DtaCtrl->head )
  340.             DtaCtrl->head->ret = errLevel;
  341.         DTA_flush( DtaCtrl );
  342.         DTA_freeCtrl( DtaCtrl );
  343.         DtaCtrl = NULL;
  344.     }
  345.  
  346.     KBF_sysEnd();
  347.     DSP_pcl_sysEnd();
  348.  
  349.     reset24h();
  350.  
  351.     pcl_exit(0);
  352.     exit( errLevel );
  353. }
  354.  
  355. int        LHX_putc( int ch )
  356. {
  357.     BREAK_CHECK();
  358.  
  359.     ch &= 0xFF;
  360.     if ( ch == '\n' )
  361.     {    CNS_puts( LhxCns,"\r\n");
  362.         LHX_dspFlush();
  363.     } else
  364.         CNS_putc( LhxCns, ch );
  365.     return (ch);
  366. }
  367.  
  368. int        LHX_fputc( int ch, FILE